package io.renren.minimito.service.impl;

import com.alibaba.druid.util.StringUtils;
import io.renren.minimito.entity.ImUserEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.minimito.dao.ImMsgDao;
import io.renren.minimito.entity.ImMsgEntity;
import io.renren.minimito.service.ImMsgService;


@Service("imMsgService")
public class ImMsgServiceImpl extends ServiceImpl<ImMsgDao, ImMsgEntity> implements ImMsgService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<ImMsgEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id",key)
                    .or().eq("send_user_id",key)
                    .or().eq("accept_user_id",key)
                    .or().like("message",key)
            ;
        }
        IPage<ImMsgEntity> page = this.page(
                new Query<ImMsgEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}